package com.dp;

public class Solution46 {
    public int maxSubArray(int[] nums) {
        int sum = 0;
        int max= Integer.MIN_VALUE;
        for (int num : nums) {
            if (sum < 0) {
                sum = 0;
            }
            sum += num;
            max = Math.max(sum, max);
        }
        return max;
    }
}
